package ThreadSecurity;

public class SaleThread3 implements Runnable{

    private int tickets = 10;

    private synchronized void saleTickets(){

        if(tickets > 0){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"窗口正在出售第"+ tickets-- +"张票~");
        }

    }

    @Override
    public void run() {
        while (true){
            this.saleTickets();
        }
    }

    public static void main(String[] args) {

        SaleThread3 s = new SaleThread3();
        new Thread(s,"1").start();
        new Thread(s,"2").start();
        new Thread(s,"3").start();
        new Thread(s,"4").start();

    }
}
